﻿using Coldairarrow.Entity.Backstage.TheRules;
using Coldairarrow.Entity.Backstage.UserData;
using Coldairarrow.Entity.Base_Company;
using Coldairarrow.Entity.BTB_StaffUsers;
using Coldairarrow.Entity.Frontstage.Valickets;
using Coldairarrow.Entity.Goods;
using Coldairarrow.IBusiness;
using Coldairarrow.Util;
using EFCore.Sharding;
using LinqKit;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;

namespace Coldairarrow.Business.Base_Company
{
    public class BTB_Company_VisitLogBusiness : BaseBusiness<BTB_Company_VisitLog>, IBTB_Company_VisitLogBusiness, ITransientDependency
    {
        readonly IOperator _operator;
        public BTB_Company_VisitLogBusiness(IDbAccessor db, IOperator @operator)
            : base(db)
        {
            _operator = @operator;
        }

        #region 外部接口

        public async Task<PageResult<BTB_Company_VisitLog>> GetDataListAsync(PageInput<ConditionDTO> input)
        {
            var q = GetIQueryable();
            var where = LinqHelper.True<BTB_Company_VisitLog>();
            var search = input.Search;

            //筛选
            if (!search.Condition.IsNullOrEmpty() && !search.Keyword.IsNullOrEmpty())
            {
                var newWhere = DynamicExpressionParser.ParseLambda<BTB_Company_VisitLog, bool>(
                    ParsingConfig.Default, false, $@"{search.Condition}.Contains(@0)", search.Keyword);
                where = where.And(newWhere);
            }

            return await q.Where(where).GetPageResultAsync(input);
        }

        public async Task<BTB_Company_VisitLog> GetTheDataAsync(string id)
        {
            return await GetEntityAsync(id);
        }

        public async Task AddDataAsync(BTB_Company_VisitLog data)
        {
            await InsertAsync(data);
        }

        public async Task UpdateDataAsync(BTB_Company_VisitLog data)
        {
            await UpdateAsync(data);
        }

        public async Task DeleteDataAsync(List<string> ids)
        {
            await DeleteAsync(ids);
        }


        #region //PV、UV、IP
        /// <summary>
        /// 获取总PV访问量
        /// </summary>
        /// <returns></returns>
        public int GetPVCount()
        {
            int val = 0;
            var cId = _operator.Property.CompanyId;

            val = GetIQueryable().Where(x => x.CompanyId == cId).Count();
            return val;
        }
        /// <summary>
        /// 获取总访问UV量
        /// </summary>
        /// <returns></returns>
        public int GetUVCount()
        {
            int val = 0;

            var cId = _operator.Property.CompanyId;
            val = GetIQueryable().Where(x => x.CompanyId == cId).Select(x => x.VisitSession).Distinct().Count();

            return val;
        }

        /// <summary>
        /// 获取总访问IP量
        /// </summary>
        /// <returns></returns>
        public int GetIPCount()
        {
            int val = 0;

            var cId = _operator.Property.CompanyId;
            val = GetIQueryable().Where(x => x.CompanyId == cId).Select(x => x.VisitIP).Distinct().Count();

            return val;
        }
        #endregion

        /// <summary>
        /// 后台——用户积分消费记录查看
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<object> GetPointLog(PageInput<SearchDTO> input)
        {
            var q = (from a in Db.GetIQueryable<BS_UserPUseLog>()
                    join b in Db.GetIQueryable<BTB_StaffUser>() on a.CreatorId equals b.id
                    select new PointLogDTO
                    {
                        Id = a.Id,
                        NickName = b.NickName,
                        RealName = b.RealName,
                        Sex = b.Sex,
                        Phone = b.phone,
                        HeadUrl = b.HeadPortrait,
                        HeadType = b.HeadType,
                        PType = a.Type,
                        Sorce = a.Purpose,
                        Point = a.PointNum,
                        CreateTime = a.CreateTime
                    })
                    .WhereIf(!input.Search.KeyWord.IsNullOrEmpty(),x => x.NickName.Contains(input.Search.KeyWord) || x.RealName.Contains(input.Search.KeyWord) || x.Phone.Contains(input.Search.KeyWord))
                    .WhereIf(input.Search.StartTime.HasValue, x => x.CreateTime >= input.Search.StartTime)
                    .WhereIf(input.Search.EndTime.HasValue, x => x.CreateTime < input.Search.EndTime);

            int income = q.Where(x => x.PType == 0).Sum(x => (int)x.Point);
            int expend = q.Where(x => x.PType == -1).Sum(x => (int)x.Point);

            input.SortField = "CreateTime";
            input.SortType = "desc";
            var data= await q.GetPageResultAsync(input);

            var sumData = new { 
                Income = income,
                Expend = expend
            };

            var sData = new {
                sumData,
                data
            };

            return sData;
        }

        /// <summary>
        /// 获取用户积分详情
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public PointLogDTO GetUThePointData(IdInputDTO input)
        {
            var model = (from a in Db.GetIQueryable<BS_UserPUseLog>()
                     join b in Db.GetIQueryable<BTB_StaffUser>() on a.CreatorId equals b.id
                     select new PointLogDTO
                     {
                         Id = a.Id,
                         NickName = b.NickName,
                         RealName = b.RealName,
                         Sex = b.Sex,
                         Phone = b.phone,
                         HeadUrl = b.HeadPortrait,
                         HeadType = b.HeadType,
                         PType = a.Type,
                         Sorce = a.Purpose,
                         Point = a.PointNum,
                         CreateTime = a.CreateTime
                     }).Where(x => x.Id.Equals(input.id)).FirstOrDefault();

            return model;
        }


        /// <summary>
        /// 后台——用户消费券列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<object> GetTicketLog(PageInput<TKTSearchDTO> input)
        {
            var thetime = DateTime.Now;

            var q = (from a in Db.GetIQueryable<BS_UserVailTicket>()
                     join b in Db.GetIQueryable<BTB_StaffUser>() on a.UserId equals b.id
                     select new UserTicketLogDTO
                     {
                         Id = a.Id,
                         NickName = b.NickName,
                         RealName = b.RealName,
                         Sex = b.Sex,
                         Phone = b.phone,
                         HeadUrl = b.HeadPortrait,
                         HeadType = b.HeadType,
                         Sorce = a.Ticket_Type == 1?"发放":"兑换",
                         TicketName = a.Ticket_Title,
                         TicketAmont = a.Ticket_Amount,
                         TicketUseMoney = a.Ticket_UseMoney,
                         TicketStartTime = a.StartTime,
                         TicketEndTime = a.EndTime,
                         CreateTime = a.CreateTime,
                         TicketState = (a.UseState == 1)? a.UseState : (a.EndTime <= thetime ? 0 : -1)
                     })
                   .WhereIf(!input.Search.KeyWord.IsNullOrEmpty(), x => x.NickName.Contains(input.Search.KeyWord) || x.RealName.Contains(input.Search.KeyWord) || x.Phone.Contains(input.Search.KeyWord))
                   .WhereIf(input.Search.StartTime.HasValue, x => x.CreateTime >= input.Search.StartTime)
                   .WhereIf(input.Search.EndTime.HasValue, x => x.CreateTime < input.Search.EndTime)
                   .WhereIf(input.Search.State.HasValue, x => x.TicketState == input.Search.State);

            int nuNum = q.Where(x => x.TicketState == 0).Count();
            int buNum = q.Where(x => x.TicketState == 1).Count();
            int odNum = q.Where(x => x.TicketState == -1).Count();

            decimal notuse = q.Where(x => x.TicketState == 0).Sum(x => (decimal)x.TicketAmont);
            decimal bused = q.Where(x => x.TicketState == 1).Sum(x => (decimal)x.TicketAmont);
            decimal overdate = q.Where(x => x.TicketState == -1).Sum(x => (decimal)x.TicketAmont);

            var data = await q.GetPageResultAsync(input);

            var sumData = new { 
                NUCount = nuNum,
                NUAmount = notuse,
                BUCount = buNum,
                BUAmont = bused,
                OVCount = odNum,
                OVAmount = overdate
            };

            var sData = new
            {
                sumData,
                data
            };

            return sData;
        }

        /// <summary>
        /// 获取用户优惠券记录详情
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public UserTicketLogDTO GetTheTicketLogData(IdInputDTO input)
        {
            var thetime = DateTime.Now;
            var model = (from a in Db.GetIQueryable<BS_UserVailTicket>()
                     join b in Db.GetIQueryable<BTB_StaffUser>() on a.UserId equals b.id
                     select new UserTicketLogDTO
                     {
                         Id = a.Id,
                         NickName = b.NickName,
                         RealName = b.RealName,
                         Sex = b.Sex,
                         Phone = b.phone,
                         HeadUrl = b.HeadPortrait,
                         HeadType = b.HeadType,
                         Sorce = a.Ticket_Type == 1 ? "发放" : "兑换",
                         TicketName = a.Ticket_Title,
                         TicketAmont = a.Ticket_Amount,
                         TicketUseMoney = a.Ticket_UseMoney,
                         TicketStartTime = a.StartTime,
                         TicketEndTime = a.EndTime,
                         CreateTime = a.CreateTime,
                         TicketState = (a.UseState == 1) ? a.UseState : (a.EndTime <= thetime ? 0 : -1)
                     }).Where(x => x.Id.Equals(input.id)).FirstOrDefault();

            return model;
        }

        /// <summary>
        /// 后台——获取收益记录
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<object> GetUserRebateLogs(PageInput<RBTSearcDTO> input)
        {
            var q = (from a in Db.GetIQueryable<BS_UserRebate>()
                    join b in Db.GetIQueryable<BTB_StaffUser>() on a.SUserId equals b.id into ab
                    from b in ab.DefaultIfEmpty()
                    join c in Db.GetIQueryable<BTB_StaffUser>() on a.XFUserId equals c.id into ac
                    from c in ac.DefaultIfEmpty()
                    select new UserRebateLogDTO
                    {
                        Id = a.Id,
                        FUserName = b.NickName,
                        FRealName = b.RealName,
                        FSex = b.Sex,
                        FHeadUrl = b.HeadPortrait,
                        FHeadType = b.HeadType,
                        XHeadType = c.HeadType,
                        XUserName = c.NickName,
                        XRealName = c.RealName,
                        XSex = c.Sex,
                        XHeadUrl = c.HeadPortrait,
                        Note = a.Note,
                        RType = a.Type,
                        OrderId = a.OrderId,
                        GoodsName = a.GoodsName,
                        GoodsItemName = a.GoodsItemName,
                        GoodsPrice = a.GoodsPrice,
                        GoodsNum = a.GoodsNum,
                        GoodsAmont = a.OrderMoney,
                        ReturnDiscount = a.ReturnDiscount,
                        ReturnMoney = a.ReturnMoney,
                        CreateTime = a.CreateTime
                    })
                   .WhereIf(!input.Search.FKeyWord.IsNullOrEmpty(), x => x.FUserName.Contains(input.Search.FKeyWord) || x.FRealName.Contains(input.Search.FKeyWord) || x.FPhone.Contains(input.Search.FKeyWord))
                   .WhereIf(!input.Search.XKeyWord.IsNullOrEmpty(), x => x.XUserName.Contains(input.Search.XKeyWord) || x.XRealName.Contains(input.Search.XKeyWord) || x.XPhone.Contains(input.Search.XKeyWord))
                   .WhereIf(input.Search.StartTime.HasValue, x => x.CreateTime >= input.Search.StartTime)
                   .WhereIf(input.Search.EndTime.HasValue, x => x.CreateTime < input.Search.EndTime)
                   .WhereIf(input.Search.RType.HasValue, x => x.RType == input.Search.RType);

            decimal rebate = q.Where(x => x.RType == 0).Sum(x => (decimal)x.ReturnMoney);
            decimal reback = q.Where(x => x.RType == 1).Sum(x => (decimal)x.ReturnMoney);
            decimal output = q.Where(x => x.RType == 2).Sum(x => (decimal)x.ReturnMoney);

            var data = await q.GetPageResultAsync(input);

            var sumData = new
            {
                DebateSum = rebate,
                RebackSum = reback,
                OutputSum = output
            };

            var sData = new
            {
                sumData,
                data
            };

            return sData;
        }

        /// <summary>
        /// 获取用户收益/体现记录详情
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public UserRebateLogDTO GetTheUserRebateLogData(IdInputDTO input)
        {
            var model = (from a in Db.GetIQueryable<BS_UserRebate>()
                     join b in Db.GetIQueryable<BTB_StaffUser>() on a.SUserId equals b.id into ab
                     from b in ab.DefaultIfEmpty()
                     join c in Db.GetIQueryable<BTB_StaffUser>() on a.XFUserId equals c.id into ac
                     from c in ac.DefaultIfEmpty()
                     select new UserRebateLogDTO
                     {
                         Id = a.Id,
                         FUserName = b.NickName,
                         FRealName = b.RealName,
                         FSex = b.Sex,
                         FHeadUrl = b.HeadPortrait,
                         XUserName = c.NickName,
                         XRealName = c.RealName,
                         XSex = c.Sex,
                         XHeadUrl = c.HeadPortrait,
                         FHeadType = b.HeadType,
                         XHeadType = c.HeadType,
                         Note = a.Note,
                         RType = a.Type,
                         OrderId = a.OrderId,
                         GoodsName = a.GoodsName,
                         GoodsItemName = a.GoodsItemName,
                         GoodsPrice = a.GoodsPrice,
                         GoodsNum = a.GoodsNum,
                         GoodsAmont = a.OrderMoney,
                         ReturnDiscount = a.ReturnDiscount,
                         ReturnMoney = a.ReturnMoney,
                         CreateTime = a.CreateTime
                     }).Where(x => x.Id.Equals(input.id)).FirstOrDefault();

            return model;
        }

        /// <summary>
        /// 获取用户收益统计数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<object> GetUserRebateDataAsnyc(PageInput<SearchDTO> input)
        {
            //获取拥有收益用户Id列表
            var sList = Db.GetIQueryable<BS_UserRebate>().Select(x => x.Id).Distinct().ToList();

            //获取用户列表
            var usList = Db.GetIQueryable<BTB_StaffUser>().Where(x => sList.Contains(x.id))
                   .WhereIf(!input.Search.KeyWord.IsNullOrEmpty(), x => x.NickName.Contains(input.Search.KeyWord) || x.RealName.Contains(input.Search.KeyWord) || x.phone.Contains(input.Search.KeyWord))
                   .ToList();

            int Count = usList.Count;

            var csList = usList.Skip(input.PageRows * (input.PageIndex - 1)).Take(input.PageRows).ToList();
            List<UserProfitDTO> data = new List<UserProfitDTO>();

            //获取体现规则列表
            int tDay = 30; //体现间隔天数
            decimal maxMoney = 15000; //每日最大提现额度

            var rMList = await Db.GetIQueryable<BS_ReflectRule>().OrderByDescending(x => x.CreateTime).ToListAsync();
            if (rMList.Count > 0)
            {
                tDay = rMList[0].ReflectDay;
                maxMoney = rMList[0].ReflectMoney;
            }

            //获取所有可提现额度
            var theTime = DateTime.Now;
            var sTime = DateTime.Now.AddDays(-1 * tDay);

            PageResult<UserProfitDTO> rData = new PageResult<UserProfitDTO>();
            rData.Total = Count;
            

            foreach (var item in csList)
            {
                decimal sumData = Db.GetIQueryable<BS_UserRebate>()
                    .WhereIf(input.Search.StartTime.HasValue, x => x.CreateTime >= input.Search.StartTime)
                    .WhereIf(input.Search.EndTime.HasValue, x => x.CreateTime < input.Search.EndTime)
                    .Where(x => x.SUserId.Equals(item.id) && x.Type == 0).Sum(x => x.ReturnMoney);
                //退回收益
                decimal ReturnData = Db.GetIQueryable<BS_UserRebate>()
                    .WhereIf(input.Search.StartTime.HasValue, x => x.CreateTime >= input.Search.StartTime)
                    .WhereIf(input.Search.EndTime.HasValue, x => x.CreateTime < input.Search.EndTime)
                    .Where(x => x.SUserId.Equals(item.id) && x.Type == 1).Sum(x => x.ReturnMoney);
                //已提现收益
                decimal ReflectData = Db.GetIQueryable<BS_UserRebate>()
                    .WhereIf(input.Search.StartTime.HasValue, x => x.CreateTime >= input.Search.StartTime)
                    .WhereIf(input.Search.EndTime.HasValue, x => x.CreateTime < input.Search.EndTime)
                    .Where(x => x.SUserId.Equals(item.id) && x.Type == 2).Sum(x => x.ReturnMoney);
              
               //总可提现金额
                decimal kSumData = Db.GetIQueryable<BS_UserRebate>()
                    .WhereIf(input.Search.StartTime.HasValue, x => x.CreateTime >= input.Search.StartTime)
                    .WhereIf(input.Search.EndTime.HasValue, x => x.CreateTime < input.Search.EndTime)
                    .Where(x => x.SUserId.Equals(item.id) && x.Type == 0 && x.CreateTime <= sTime).Sum(x => x.ReturnMoney);

                //可提现中退回金额
                decimal stkSumData = Db.GetIQueryable<BS_UserRebate>().Where(x => x.SUserId.Equals(item.id) && x.Type == 1 && x.CreateTime <= sTime).Sum(x => x.ReturnMoney);

                //获取今天已提现额
                var strTime = DateTime.Parse(theTime.ToString("yyyy-MM-dd"));
                var endTime = strTime.AddDays(1);
                decimal jySumData = Db.GetIQueryable<BS_UserRebate>()
                    .WhereIf(input.Search.StartTime.HasValue, x => x.CreateTime >= input.Search.StartTime)
                    .WhereIf(input.Search.EndTime.HasValue, x => x.CreateTime < input.Search.EndTime)
                    .Where(x => x.SUserId.Equals(item.id) && x.Type == 2 && x.CreateTime >= strTime && x.CreateTime < endTime).Sum(x => x.ReturnMoney);

                //可提现=总可提现-已提现-已退回
                decimal syktxData = kSumData - ReflectData - stkSumData;
                decimal jrktData = 0;

                if (syktxData + jySumData > maxMoney)
                {
                    jrktData = maxMoney;
                }
                else
                {
                    jrktData = syktxData;
                }

                UserProfitDTO model = new UserProfitDTO();
                model.Id = item.id;
                model.NickName = item.NickName;
                model.RealName = item.RealName;
                model.Sex = item.Serial;
                model.Phone = item.phone;
                model.HeadType = item.HeadType;
                model.HeadUrl = item.HeadPortrait;
                model.SumProfit = sumData;
                model.ReturnProfit = ReturnData;
                model.CashProfit = kSumData - stkSumData;
                model.CashedProfit = ReflectData;
                model.NotCashProfit = syktxData;
                model.TodayCashProfit = jrktData;
                model.TodayCashedProfit = jySumData;
                model.TodayNotCashProfit = jrktData - jySumData;
                model.JoinTime = item.CreateTime;

                data.Add(model);
            }

            rData.Data = data;

            #region//获取统计数据
            decimal TsumData = Db.GetIQueryable<BS_UserRebate>()
                  .WhereIf(input.Search.StartTime.HasValue, x => x.CreateTime >= input.Search.StartTime)
                  .WhereIf(input.Search.EndTime.HasValue, x => x.CreateTime < input.Search.EndTime)
                  .Where(x => sList.Contains(x.SUserId) && x.Type == 0).Sum(x => x.ReturnMoney);
            //退回收益
            decimal TReturnData = Db.GetIQueryable<BS_UserRebate>()
                .WhereIf(input.Search.StartTime.HasValue, x => x.CreateTime >= input.Search.StartTime)
                .WhereIf(input.Search.EndTime.HasValue, x => x.CreateTime < input.Search.EndTime)
                .Where(x => sList.Contains(x.SUserId) && x.Type == 1).Sum(x => x.ReturnMoney);
            //已提现收益
            decimal TReflectData = Db.GetIQueryable<BS_UserRebate>()
                .WhereIf(input.Search.StartTime.HasValue, x => x.CreateTime >= input.Search.StartTime)
                .WhereIf(input.Search.EndTime.HasValue, x => x.CreateTime < input.Search.EndTime)
                .Where(x => sList.Contains(x.SUserId) && x.Type == 2).Sum(x => x.ReturnMoney);

            //总可提现金额
            decimal TkSumData = Db.GetIQueryable<BS_UserRebate>()
                .WhereIf(input.Search.StartTime.HasValue, x => x.CreateTime >= input.Search.StartTime)
                .WhereIf(input.Search.EndTime.HasValue, x => x.CreateTime < input.Search.EndTime)
                .Where(x => sList.Contains(x.SUserId) && x.Type == 0 && x.CreateTime <= sTime).Sum(x => x.ReturnMoney);

            //可提现中退回金额
            decimal TstkSumData = Db.GetIQueryable<BS_UserRebate>().Where(x => sList.Contains(x.SUserId) && x.Type == 1 && x.CreateTime <= sTime).Sum(x => x.ReturnMoney);

            var SumData = new { 
                SumRebate = TstkSumData - TReturnData,
                CTXRebate = TkSumData - TstkSumData,
                ReflectRebate = TReflectData,
                SumNotRebate = TstkSumData - TReturnData - TReflectData,
                KTXNotRebate = TkSumData - TstkSumData - TReflectData
            };

            #endregion

            var sData = new
            {
                sumData = SumData,
                data = rData
            };

            return sData;
        }

        public UserProfitDTO GetTheUserRebateData(IdInputDTO input)
        {

            //获取用户列表
            var usList = Db.GetIQueryable<BTB_StaffUser>().Where(x => x.id.Equals(input.id)).ToList();

            List<UserProfitDTO> data = new List<UserProfitDTO>();

            //获取体现规则列表
            int tDay = 30; //体现间隔天数
            decimal maxMoney = 15000; //每日最大提现额度

            var rMList =  Db.GetIQueryable<BS_ReflectRule>().OrderByDescending(x => x.CreateTime).ToList();
            if (rMList.Count > 0)
            {
                tDay = rMList[0].ReflectDay;
                maxMoney = rMList[0].ReflectMoney;
            }

            //获取所有可提现额度
            var theTime = DateTime.Now;
            var sTime = DateTime.Now.AddDays(-1 * tDay);

            foreach (var item in usList)
            {
                decimal sumData = Db.GetIQueryable<BS_UserRebate>()
                    .Where(x => x.SUserId.Equals(item.id) && x.Type == 0).Sum(x => x.ReturnMoney);
                //退回收益
                decimal ReturnData = Db.GetIQueryable<BS_UserRebate>()
                    .Where(x => x.SUserId.Equals(item.id) && x.Type == 1).Sum(x => x.ReturnMoney);
                //已提现收益
                decimal ReflectData = Db.GetIQueryable<BS_UserRebate>()
                    .Where(x => x.SUserId.Equals(item.id) && x.Type == 2).Sum(x => x.ReturnMoney);

                //总可提现金额
                decimal kSumData = Db.GetIQueryable<BS_UserRebate>()
                    .Where(x => x.SUserId.Equals(item.id) && x.Type == 0 && x.CreateTime <= sTime).Sum(x => x.ReturnMoney);

                //可提现中退回金额
                decimal stkSumData = Db.GetIQueryable<BS_UserRebate>().Where(x => x.SUserId.Equals(item.id) && x.Type == 1 && x.CreateTime <= sTime).Sum(x => x.ReturnMoney);

                //获取今天已提现额
                var strTime = DateTime.Parse(theTime.ToString("yyyy-MM-dd"));
                var endTime = strTime.AddDays(1);
                decimal jySumData = Db.GetIQueryable<BS_UserRebate>()
                    .Where(x => x.SUserId.Equals(item.id) && x.Type == 2 && x.CreateTime >= strTime && x.CreateTime < endTime).Sum(x => x.ReturnMoney);

                //可提现=总可提现-已提现-已退回
                decimal syktxData = kSumData - ReflectData - stkSumData;
                decimal jrktData = 0;

                if (syktxData + jySumData > maxMoney)
                {
                    jrktData = maxMoney;
                }
                else
                {
                    jrktData = syktxData;
                }

                UserProfitDTO model = new UserProfitDTO();
                model.Id = item.id;
                model.NickName = item.NickName;
                model.RealName = item.RealName;
                model.Sex = item.Serial;
                model.Phone = item.phone;
                model.HeadType = item.HeadType;
                model.HeadUrl = item.HeadPortrait;
                model.SumProfit = sumData;
                model.ReturnProfit = ReturnData;
                model.CashProfit = kSumData - stkSumData;
                model.CashedProfit = ReflectData;
                model.NotCashProfit = syktxData;
                model.TodayCashProfit = jrktData;
                model.TodayCashedProfit = jySumData;
                model.TodayNotCashProfit = jrktData - jySumData;
                model.JoinTime = item.CreateTime;

                data.Add(model);
            }

            return data.FirstOrDefault();
        }

        #endregion

        #region 私有成员

        #endregion
    }
}